package com.cykj.v_m_sprintboot.controller;

import com.cykj.v_m_sprintboot.bean.*;
import com.cykj.v_m_sprintboot.service.ApproveService;
import com.cykj.v_m_sprintboot.service.TbOpratorService;
import com.cykj.v_m_sprintboot.tool.JsonXMLUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: wei
 * @date: 2021/9/26 20:20
 */

@RestController
public class ApproveController {
    @Autowired
    private ApproveService approveService;

    @Autowired
    private TbOpratorService tbOpratorService;


    //获取退货数据表格的方法
    @RequestMapping("/getReturnAppList")
   @ResponseBody
    public Map<String, Object> getReturnAppList(@RequestBody PageInf pageInf)  {
        Map<String,Object> nameMap = new HashMap<>();
        nameMap.put("PageInf", pageInf);
        nameMap.put("count", approveService.findid());
        nameMap.put("ReAppList", approveService.findReturnApplication(new RowBounds((pageInf.getPage() -1) * pageInf.getSize(),pageInf.getSize())));
        return nameMap;
        }

    //退货审核
    @RequestMapping("changstate")
    @ResponseBody
    public boolean  changstate(@RequestBody TbReturnApplication tbReturnApplication){
        System.out.println(tbReturnApplication.getId());
        int id = (int) tbReturnApplication.getId();
        String applicationState = tbReturnApplication.getApplicationState();
        String remarks = tbReturnApplication.getRemarks();
        boolean flag=approveService.changRAstate(id, applicationState,remarks);

        if (flag){
            return true;
        }else {
            return false;
        }

    }

    // 耗损审批日期条件查询
    @RequestMapping("/RAppShenCha")
    @ResponseBody
    public Map<String,Object> RAppShenCha(@RequestBody Map<String,Object> map) throws Exception {
        PageInf pageInf = null;
        TbReturnApplication tbReturnApplication = null;
        if (map.get("pageInf")!=null){
            pageInf = JsonXMLUtils.map2obj((Map<String, Object>)map.get("pageInf"),PageInf.class);
        }
        if (map.get("tbReturnApplication")!=null){
            tbReturnApplication = JsonXMLUtils.map2obj((Map<String, Object>) map.get("tbReturnApplication"),TbReturnApplication.class);
        }
        System.out.println("供应商----查询数据"+tbReturnApplication);
        System.out.println("供应商----查询数据");

        Map<String,Object> nameMap = new HashMap<>();
        String startDate =  tbReturnApplication.getReturnTime();//开始日期
        String overDate = tbReturnApplication.getOverDate();//结束日期
        System.out.println("退货开始日期是多少-----------"+startDate);
        System.out.println("退货商结束日期是多少-----------"+overDate);
        nameMap.put("pageConfig",pageInf);
        nameMap.put("count", approveService.findid());
        nameMap.put("SelectList",approveService.findRAppDate(startDate,overDate,new RowBounds((pageInf.getPage() -1) * pageInf.getSize(),pageInf.getSize())));
        return nameMap;
    }


//<耗损审批表-TbLossApplication-------------------------------->
    //获取耗损数据表格的方法
    @RequestMapping("/getLossList")
    @ResponseBody
    public Map<String, Object> getLossList(@RequestBody PageInf pageInf)  {
        Map<String,Object> nameMap = new HashMap<>();
        nameMap.put("PageInf", pageInf);
        nameMap.put("count", approveService.finLossdid());
        nameMap.put("LossList", approveService.findLossApplication(new RowBounds((pageInf.getPage() -1) * pageInf.getSize(),pageInf.getSize())));
        return nameMap;
    }

    //耗损审核
    @RequestMapping("changLossstate")
    @ResponseBody
    public boolean  changLossstate(@RequestBody TbLossApplication tbLossApplication){

        System.out.println("耗损审批啊---------------");
        System.out.println(tbLossApplication.getId());
        int id = (int) tbLossApplication.getId();
        String approveState = tbLossApplication.getApproveState();
        String remarks = tbLossApplication.getRemarks();
        boolean flag=approveService.changLossstate(id, approveState,remarks);

        if (flag){
            return true;
        }else {
            return false;
        }

    }

    // 耗损审批日期条件查询
    @RequestMapping("/LossShenCha")
    @ResponseBody
    public Map<String,Object> LossShenCha(@RequestBody Map<String,Object> map) throws Exception {
        PageInf pageInf = null;
        TbLossApplication tbLossApplication = null;
        if (map.get("pageInf")!=null){
            pageInf = JsonXMLUtils.map2obj((Map<String, Object>)map.get("pageInf"),PageInf.class);
        }
        if (map.get("tbLossApplication")!=null){
            tbLossApplication = JsonXMLUtils.map2obj((Map<String, Object>) map.get("tbLossApplication"),TbLossApplication.class);
        }
        System.out.println("供应商----查询数据"+tbLossApplication);
        System.out.println("供应商----查询数据");

        Map<String,Object> nameMap = new HashMap<>();
        String startDate =  tbLossApplication.getLossTime();//开始日期
        String overDate = tbLossApplication.getOverDate();//结束日期
        System.out.println("损耗开始日期是多少-----------"+startDate);
        System.out.println("损耗商结束日期是多少-----------"+overDate);
        nameMap.put("pageConfig",pageInf);
        nameMap.put("count", approveService.finLossdid());
        nameMap.put("SelectList",approveService.findLossDate(startDate,overDate,new RowBounds((pageInf.getPage() -1) * pageInf.getSize(),pageInf.getSize())));
        return nameMap;
    }

//    供应商审批-TbSupplier---------------
//获取供应商数据表格的方法
@RequestMapping("/getSuppList")
@ResponseBody
public Map<String, Object> getSuppList(@RequestBody PageInf pageInf)  {

    Map<String,Object> nameMap = new HashMap<>();
    nameMap.put("PageInf", pageInf);
    nameMap.put("count", approveService.finSuppdid());
    nameMap.put("SuppList", approveService.findSuppApplication(new RowBounds((pageInf.getPage() -1) * pageInf.getSize(),pageInf.getSize())));
    return nameMap;
}

    //供应商审核
    @RequestMapping("changSuppstate")
    @ResponseBody
    public boolean  changSuppstate(@RequestBody TbSupplier tbSupplier){
        System.out.println("qqqqqqqqqqqqq供应商审批啊---------------");
        System.out.println(tbSupplier.getSupplierId());
        int id = (int) tbSupplier.getSupplierId();
        String approveState = tbSupplier.getApproveState();
        String remarks = tbSupplier.getRemarks();
        boolean flag=approveService.changSuppstate(id, approveState,remarks);

        if (flag){
            return true;
        }else {
            return false;
        }

    }




    // 供应商审批日期条件查询
    @RequestMapping("/SuShenCha")
    @ResponseBody
    public Map<String,Object> SuShedddnCha(@RequestBody Map<String,Object> map) throws Exception {
        PageInf pageInf = null;
        TbSupplier tbSupplier = null;
        if (map.get("pageInf")!=null){
            pageInf = JsonXMLUtils.map2obj((Map<String, Object>)map.get("pageInf"),PageInf.class);
        }
        if (map.get("tbSupplier")!=null){
            tbSupplier = JsonXMLUtils.map2obj((Map<String, Object>) map.get("tbSupplier"),TbSupplier.class);
        }
        System.out.println("供应商----查询数据"+tbSupplier);
        System.out.println("供应商----查询数据");

        Map<String,Object> nameMap = new HashMap<>();
        String startDate =  tbSupplier.getSupplierTime();//开始日期
        String overDate = tbSupplier.getOverDate();//结束日期
        System.out.println("供应商开始日期是多少-----------"+startDate);
        System.out.println("供应商结束日期是多少-----------"+overDate);
        nameMap.put("pageConfig",pageInf);
        nameMap.put("count", approveService.finSuppdid());
        nameMap.put("SelectList",approveService.findSuDate(startDate,overDate,new RowBounds((pageInf.getPage() -1) * pageInf.getSize(),pageInf.getSize())));
        return nameMap;
    }
//    运营商审批---------------------
//运营商审批-
@RequestMapping("changOAstate")
@ResponseBody
public boolean  changOAstate(@RequestBody TbOperator tbOperator){
    System.out.println("qqqqqqqqqqqqq供应商审批啊---------------");
    System.out.println(tbOperator.getOperatorId());
    int id = (int) tbOperator.getOperatorId();
    String approveState = tbOperator.getApproveState();
    String remarks = tbOperator.getRemarks();
    boolean flag=approveService.changOAstate(id, approveState,remarks);

    if (flag){
        return true;
    }else {
        return false;
    }

}

    // 运营商审批日期条件查询
    @RequestMapping("/OpShenCha")
    @ResponseBody
    public Map<String,Object> findSite(@RequestBody Map<String,Object> map) throws Exception {
        PageInf pageInf = null;
        TbOperator tbOperator = null;
        if (map.get("pageInf")!=null){
            pageInf = JsonXMLUtils.map2obj((Map<String, Object>)map.get("pageInf"),PageInf.class);
        }
        if (map.get("tbOperator")!=null){
            tbOperator = JsonXMLUtils.map2obj((Map<String, Object>) map.get("tbOperator"),TbOperator.class);
        }
        System.out.println("运营商----查询数据"+tbOperator);
        System.out.println("运营商----查询数据");
        System.out.println(tbOperator.getOperatorTime()+" "+pageInf.getPage());
        Map<String,Object> nameMap = new HashMap<>();
        String startDate =  tbOperator.getOperatorTime();//开始日期
        String overDate = tbOperator.getOverDate();//结束日期
        System.out.println("开始日期是多少-----------"+startDate);
        System.out.println("结束日期是多少-----------"+overDate);
        nameMap.put("pageConfig",pageInf);
        nameMap.put("count", approveService.findid());
        nameMap.put("SelectList",approveService.findOpData(startDate,overDate,new RowBounds((pageInf.getPage() -1) * pageInf.getSize(),pageInf.getSize())));
        return nameMap;
    }
}
